package springmvc.common;
import java.util.ArrayList;  
import java.util.List;  
  
public class CriteriaExample {  
    protected List<OrderByCase> orderByList;  
  
    protected boolean distinct;

    public List<Criteria> getCriteriaList() {
        return criteriaList;
    }

    public void setCriteriaList(List<Criteria> criteriaList) {
        this.criteriaList = criteriaList;
    }

    protected List<Criteria> criteriaList;
  
    public List<OrderByCase> getOrderByList() {  
    return orderByList;  
    }  
  
    public void setOrderByList(List<OrderByCase> orderByList) {  
    this.orderByList = orderByList;  
    }  
  
    public boolean isDistinct() {  
    return distinct;  
    }  
  
    public void setDistinct(boolean distinct) {  
    this.distinct = distinct;  
    }  
  

  
    @Override  
    public String toString() {  
    return "CriteriaExample [orderByList=" + orderByList + ", distinct=" + distinct + ", criteriaList="  
        + criteriaList + ", getOrderByList()=" + getOrderByList() + ", isDistinct()=" + isDistinct()
        + ", getCriteriaList()=" + getCriteriaList() + ", getClass()=" + getClass() + ", hashCode()="
        + hashCode() + ", toString()=" + super.toString() + "]";  
    }  
  
    public CriteriaExample addOrderByCase(String field, String direction) {  
    if (this.orderByList == null) {  
        this.orderByList = new ArrayList<OrderByCase>();  
    }  
    this.orderByList.add(new OrderByCase(field, direction));  
    return (CriteriaExample) this;  
    }  
  
    public CriteriaExample addCriteria(Criteria criteria) {  
    if (this.criteriaList == null) {
        this.criteriaList = new ArrayList<Criteria>();
    }  
    this.criteriaList.add(criteria);
    return (CriteriaExample) this;  
    }  
  
    public static class OrderByCase {  
    public static String ASC = "ASC";  
    public static String DESC = "DESC";  
    private String condition;  
    private String direction; // ASC,DESC  
  
    public String getCondition() {  
        return condition;  
    }  
  
    public void setCondition(String condition) {  
        this.condition = condition;  
    }  
  
    public String getDirection() {  
        return direction;  
    }  
  
    public void setDirection(String direction) {  
        this.direction = direction;  
    }  
  
    public OrderByCase(String condition, String direction) {  
        super();  
        this.condition = condition;  
        this.direction = direction;  
    }  
  
    @Override  
    public String toString() {  
        return "OrderByCase [condition=" + condition + ", direction=" + direction + "]";  
    }  
    }  
  
    protected abstract static class GeneratedCriteria {  
    protected List<Criterion> criteria;
  
    protected GeneratedCriteria() {  
        super();  
        criteria = new ArrayList<Criterion>();
    }  
  
    public boolean isValid() {  
        return criteria.size() > 0;  
    }  
  
    public List<Criterion> getAllCriteria() {
        return criteria;  
    }  
  
    public List<Criterion> getCriteria() {
        return criteria;  
    }  
  
    protected void addCriterion(String condition, String property) {  
        if (condition == null) {  
        throw new RuntimeException("condition for " + property + " cannot be null");  
        }  
  
        criteria.add(new Criterion(condition));
    }  
  
    protected void addCriterion(String condition, Object value, String property) {  
        if (condition == null) {  
        throw new RuntimeException("condition for " + property + " cannot be null");  
        }  
        if (value == null) {  
        throw new RuntimeException("Value for " + property + " cannot be null");  
        }  
        criteria.add(new Criterion(condition, value));
    }  
  
    protected void addCriterion(String condition, Object value1, Object value2, String property) {  
        if (condition == null) {  
        throw new RuntimeException("condition for " + property + " cannot be null");  
        }  
        if (value1 == null || value2 == null) {  
        throw new RuntimeException("Between values for " + property + " cannot be null");  
        }  
        criteria.add(new Criterion(condition, value1, value2));
    }  
  
    public Criteria equal(String field, Object value) {  
        addCriterion(field + " =", value, field);  
        return (Criteria) this;  
    }  
  
    public Criteria notEqual(String field, Object value) {  
        addCriterion(field + " <> ", value, field);  
        return (Criteria) this;  
    }  
  
    public Criteria greaterThan(String field, Object value) {  
        addCriterion(field + " > ", value, field);  
        return (Criteria) this;  
    }  
  
    public Criteria lessThan(String field, Object value) {  
        addCriterion(field + " < ", value, field);  
        return (Criteria) this;  
    }  
  
    public Criteria lessThanOrEqual(String field, Object value) {  
        addCriterion(field + " <= ", value, field);  
        return (Criteria) this;  
    }  
    
    public Criteria greaterThanOrEqual(String field, Object value) {  
        addCriterion(field + " >= ", value, field);  
        return (Criteria) this;  
    }  
  
    public <T> Criteria in(String field, List<T> valueList) {  
        addCriterion(field + " in ", valueList, field);  
        return (Criteria) this;  
    }  
  
    public <T> Criteria notIn(String field, List<T> valueList) {  
        addCriterion(field + " not in ", valueList, field);  
        return (Criteria) this;  
    }  
  
    public Criteria between(String field, Object value1, Object value2) {  
        addCriterion(field + " between ", value1, value2, field);  
        return (Criteria) this;  
    }  
  
    public Criteria notBetween(String field, Object value1, Object value2) {  
        addCriterion(field + " not between ", value1, value2, field);  
        return (Criteria) this;  
    }  
  
    public Criteria isNull(String field) {  
        addCriterion(field + " is null ", field);  
        return (Criteria) this;  
    }  
  
    public Criteria isNotNull(String field) {  
        addCriterion(field + " is not null ", field);  
        return (Criteria) this;  
    }  
  
    public Criteria like(String field, Object value) {  
        addCriterion(field + " like concat(concat('%',\"" + value + "\",'%'))", field);  
        return (Criteria) this;  
    }  
  
    public Criteria notLike(String field, Object value) {  
        addCriterion(field + " not like concat(concat('%',\"" + value + "\",'%'))", field);  
        // addCriterion(field + " not like ", value, field);  
        return (Criteria) this;  
    }  
    }  
  
    public static class Criteria extends GeneratedCriteria {  
    public Criteria() {  
        super();  
    }  
  
    @Override  
    public String toString() {  
        return "Criteria [criteria=" + criteria + ", isValid()=" + isValid() + ", getAllCriteria()="  
            + getAllCriteria() + ", getCriteria()=" + getCriteria() + ", getClass()=" + getClass()  
            + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";  
    }  
  
    }  
  
    public static class Criterion {
    private String condition;

    private Object value;

    private Object secondValue;

    private boolean noValue;

    private boolean singleValue;

    private boolean betweenValue;

    private boolean listValue;

    private String typeHandler;

    public String getCondition() {
        return condition;
    }

    public Object getValue() {
        return value;
    }

    public Object getSecondValue() {
        return secondValue;
    }

    public boolean isNoValue() {
        return noValue;
    }

    public boolean isSingleValue() {
        return singleValue;
    }

    public boolean isBetweenValue() {
        return betweenValue;
    }

    public boolean isListValue() {
        return listValue;
    }

    public String getTypeHandler() {
        return typeHandler;
    }

    protected Criterion(String condition) {
        super();
        this.condition = condition;
        this.typeHandler = null;
        this.noValue = true;
    }

    protected Criterion(String condition, Object value, String typeHandler) {
        super();
        this.condition = condition;
        this.value = value;
        this.typeHandler = typeHandler;
        if (value instanceof List<?>) {
        this.listValue = true;
        } else {
        this.singleValue = true;
        }
    }

    protected Criterion(String condition, Object value) {
        this(condition, value, null);
    }

    protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
        super();
        this.condition = condition;
        this.value = value;
        this.secondValue = secondValue;
        this.typeHandler = typeHandler;
        this.betweenValue = true;
    }

    protected Criterion(String condition, Object value, Object secondValue) {
        this(condition, value, secondValue, null);
    }

    @Override
    public String toString() {
        return "Criterion [condition=" + condition + ", value=" + value + ", secondValue=" + secondValue
            + ", noValue=" + noValue + ", singleValue=" + singleValue + ", betweenValue=" + betweenValue
            + ", listValue=" + listValue + ", typeHandler=" + typeHandler + "]";
    }

    }

}  